﻿using System;
using System.Collections.Generic;
using System.Linq;
using Helpers;
using TaleWorlds.CampaignSystem.Actions;
using TaleWorlds.CampaignSystem.Conversation;
using TaleWorlds.CampaignSystem.Encounters;
using TaleWorlds.CampaignSystem.Extensions;
using TaleWorlds.CampaignSystem.MapEvents;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.CampaignSystem.Party.PartyComponents;
using TaleWorlds.CampaignSystem.Roster;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.Core;
using TaleWorlds.Library;
using TaleWorlds.Localization;
using TaleWorlds.ObjectSystem;
using TaleWorlds.SaveSystem;

namespace TaleWorlds.CampaignSystem.Issues
{
	// Token: 0x02000301 RID: 769
	public class CaravanAmbushIssueBehavior : CampaignBehaviorBase
	{
		// Token: 0x06002CF0 RID: 11504 RVA: 0x000BC6FA File Offset: 0x000BA8FA
		public override void RegisterEvents()
		{
			CampaignEvents.OnCheckForIssueEvent.AddNonSerializedListener(this, new Action<Hero>(this.OnCheckForIssue));
		}

		// Token: 0x06002CF1 RID: 11505 RVA: 0x000BC714 File Offset: 0x000BA914
		private void OnCheckForIssue(Hero hero)
		{
			if (this.ConditionsHold(hero))
			{
				Settlement targetSettlement = this.GetTargetSettlement(hero.CurrentSettlement);
				if (targetSettlement != null)
				{
					Campaign.Current.IssueManager.AddPotentialIssueData(hero, new PotentialIssueData(new PotentialIssueData.StartIssueDelegate(this.OnIssueSelected), typeof(CaravanAmbushIssueBehavior.CaravanAmbushIssue), IssueBase.IssueFrequency.Common, targetSettlement));
				}
			}
		}

		// Token: 0x06002CF2 RID: 11506 RVA: 0x000BC768 File Offset: 0x000BA968
		private IssueBase OnIssueSelected(in PotentialIssueData pid, Hero issueOwner)
		{
			PotentialIssueData potentialIssueData = pid;
			return new CaravanAmbushIssueBehavior.CaravanAmbushIssue(issueOwner, potentialIssueData.RelatedObject as Settlement);
		}

		// Token: 0x06002CF3 RID: 11507 RVA: 0x000BC78E File Offset: 0x000BA98E
		private bool ConditionsHold(Hero issueGiver)
		{
			return issueGiver != null && issueGiver.IsNotable && !issueGiver.OwnedCaravans.IsEmpty<CaravanPartyComponent>() && (issueGiver.IsArtisan || issueGiver.IsMerchant);
		}

		// Token: 0x06002CF4 RID: 11508 RVA: 0x000BC7BC File Offset: 0x000BA9BC
		private Settlement GetTargetSettlement(Settlement currentSettlement)
		{
			IEnumerable<Settlement> source = from t in Settlement.All
			where t.IsTown && t != currentSettlement && t.MapFaction != null && !t.MapFaction.IsAtWarWith(currentSettlement.MapFaction) && !t.IsUnderRaid && !t.IsUnderSiege
			select t;
			if (!source.Any<Settlement>())
			{
				return null;
			}
			return source.MinBy((Settlement t) => Campaign.Current.Models.MapDistanceModel.GetDistance(t, currentSettlement));
		}

		// Token: 0x06002CF5 RID: 11509 RVA: 0x000BC809 File Offset: 0x000BAA09
		public override void SyncData(IDataStore dataStore)
		{
		}

		// Token: 0x04000D7B RID: 3451
		private const IssueBase.IssueFrequency CaravanAmbushIssueFrequency = IssueBase.IssueFrequency.Common;

		// Token: 0x02000611 RID: 1553
		public class CaravanAmbushIssue : IssueBase
		{
			// Token: 0x060049B0 RID: 18864 RVA: 0x00154539 File Offset: 0x00152739
			internal static void AutoGeneratedStaticCollectObjectsCaravanAmbushIssue(object o, List<object> collectedObjects)
			{
				((CaravanAmbushIssueBehavior.CaravanAmbushIssue)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
			}

			// Token: 0x060049B1 RID: 18865 RVA: 0x00154547 File Offset: 0x00152747
			protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
			{
				base.AutoGeneratedInstanceCollectObjects(collectedObjects);
				collectedObjects.Add(this._targetSettlement);
			}

			// Token: 0x060049B2 RID: 18866 RVA: 0x0015455C File Offset: 0x0015275C
			internal static object AutoGeneratedGetMemberValue_targetSettlement(object o)
			{
				return ((CaravanAmbushIssueBehavior.CaravanAmbushIssue)o)._targetSettlement;
			}

			// Token: 0x17000E9E RID: 3742
			// (get) Token: 0x060049B3 RID: 18867 RVA: 0x00154569 File Offset: 0x00152769
			public override IssueBase.AlternativeSolutionScaleFlag AlternativeSolutionScaleFlags
			{
				get
				{
					return IssueBase.AlternativeSolutionScaleFlag.Casualties | IssueBase.AlternativeSolutionScaleFlag.FailureRisk;
				}
			}

			// Token: 0x17000E9F RID: 3743
			// (get) Token: 0x060049B4 RID: 18868 RVA: 0x0015456D File Offset: 0x0015276D
			public override TextObject IssueBriefByIssueGiver
			{
				get
				{
					return new TextObject("{=kOxu3Lw0}Yes... I run caravans, as you may know. I lose a few to bandits from time to time, but generally my caravans are sufficiently well guarded to scare off the small gangs and move quickly enough to outrun the big ones.The problem is that there's a new bandit chief out there who knows his business, who has outfitted his men with horses and uses proper cavalry tactics.I’ve lost three caravans in a row, and I can’t afford to keep this up for long.[if:convo_stern][ib:hip]", null);
				}
			}

			// Token: 0x17000EA0 RID: 3744
			// (get) Token: 0x060049B5 RID: 18869 RVA: 0x0015457A File Offset: 0x0015277A
			public override TextObject IssueAcceptByPlayer
			{
				get
				{
					return new TextObject("{=aJcChHfj}What are you planning to do about them?", null);
				}
			}

			// Token: 0x17000EA1 RID: 3745
			// (get) Token: 0x060049B6 RID: 18870 RVA: 0x00154587 File Offset: 0x00152787
			protected override int CompanionSkillRewardXP
			{
				get
				{
					return (int)(600f + 800f * base.IssueDifficultyMultiplier);
				}
			}

			// Token: 0x17000EA2 RID: 3746
			// (get) Token: 0x060049B7 RID: 18871 RVA: 0x0015459C File Offset: 0x0015279C
			public override TextObject IssueQuestSolutionExplanationByIssueGiver
			{
				get
				{
					TextObject textObject = new TextObject("{=iWWKTOik}I've got a trick up my sleeve. We'll bait them. I've paid some of my workers to spread rumors about a particularly fat caravan laden with silverware heading out towards {TARGET_SETTLEMENT}. It is a trap, of course. I've got a bunch of mercenaries going with it, disguised as packers. But they could use some backup. Go and follow my caravan. Stay at a proper distance, until they are attacked. Then move in to finish the bandits once and for all. My caravan master will pay you {REWARD}{GOLD_ICON} when the fight is over.[if:convo_mocking_revenge][ib:confident2]", null);
					textObject.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.EncyclopediaLinkWithName);
					textObject.SetTextVariable("REWARD", this.RewardGold);
					textObject.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					return textObject;
				}
			}

			// Token: 0x17000EA3 RID: 3747
			// (get) Token: 0x060049B8 RID: 18872 RVA: 0x001545EE File Offset: 0x001527EE
			public override TextObject IssueQuestSolutionAcceptByPlayer
			{
				get
				{
					return new TextObject("{=Ov3b2b8p}I'll help you myself.", null);
				}
			}

			// Token: 0x17000EA4 RID: 3748
			// (get) Token: 0x060049B9 RID: 18873 RVA: 0x001545FB File Offset: 0x001527FB
			public override TextObject IssueAlternativeSolutionExplanationByIssueGiver
			{
				get
				{
					TextObject textObject = new TextObject("{=jiFCxZ4B}In that case you should send a good commander with some {TROOP_COUNT} men, just to be safe. And I'll send them back to you in {RETURN_DAYS} days. [if:convo_normal][ib:closed]", null);
					textObject.SetTextVariable("TROOP_COUNT", base.GetTotalAlternativeSolutionNeededMenCount());
					textObject.SetTextVariable("RETURN_DAYS", base.GetTotalAlternativeSolutionDurationInDays());
					return textObject;
				}
			}

			// Token: 0x17000EA5 RID: 3749
			// (get) Token: 0x060049BA RID: 18874 RVA: 0x0015462C File Offset: 0x0015282C
			public override TextObject IssueAlternativeSolutionAcceptByPlayer
			{
				get
				{
					TextObject textObject = new TextObject("{=XLswis9W}I will lend you one of my best lieutenants and {TROOP_COUNT} men.", null);
					textObject.SetTextVariable("TROOP_COUNT", base.GetTotalAlternativeSolutionNeededMenCount());
					textObject.SetTextVariable("RETURN_DAYS", base.GetTotalAlternativeSolutionDurationInDays());
					return textObject;
				}
			}

			// Token: 0x17000EA6 RID: 3750
			// (get) Token: 0x060049BB RID: 18875 RVA: 0x0015465D File Offset: 0x0015285D
			public override TextObject IssueDiscussAlternativeSolution
			{
				get
				{
					return new TextObject("{=L3U98ygQ}We're still preparing the ambush. I hope to have your men back to you shortly.", null);
				}
			}

			// Token: 0x17000EA7 RID: 3751
			// (get) Token: 0x060049BC RID: 18876 RVA: 0x0015466A File Offset: 0x0015286A
			public override TextObject IssueAlternativeSolutionResponseByIssueGiver
			{
				get
				{
					return new TextObject("{=Y9LNbRho}Thank you. I will put your men to good use.", null);
				}
			}

			// Token: 0x17000EA8 RID: 3752
			// (get) Token: 0x060049BD RID: 18877 RVA: 0x00154677 File Offset: 0x00152877
			public override bool IsThereLordSolution
			{
				get
				{
					return false;
				}
			}

			// Token: 0x17000EA9 RID: 3753
			// (get) Token: 0x060049BE RID: 18878 RVA: 0x0015467A File Offset: 0x0015287A
			public override TextObject Title
			{
				get
				{
					return new TextObject("{=wF7uiYzy}Caravan Ambush", null);
				}
			}

			// Token: 0x17000EAA RID: 3754
			// (get) Token: 0x060049BF RID: 18879 RVA: 0x00154688 File Offset: 0x00152888
			public override TextObject Description
			{
				get
				{
					TextObject textObject = new TextObject("{=H3B75sYi}A merchant asked you to follow a fake caravan that was sent out as a trap to destroy a particularly large and dangerous group of bandits.", null);
					StringHelpers.SetCharacterProperties("NOTABLE", base.IssueOwner.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17000EAB RID: 3755
			// (get) Token: 0x060049C0 RID: 18880 RVA: 0x001546BC File Offset: 0x001528BC
			protected override TextObject AlternativeSolutionStartLog
			{
				get
				{
					TextObject textObject = new TextObject("{=YbZYXRqt}{QUEST_GIVER.LINK} asked you to follow a caravan that he sent out as bait to destroy a particularly large and dangerous group of bandits. You ordered {COMPANION.LINK} and {TROOP_COUNT} of your men to follow the caravan from a safe distance and join in the fight once it is attacked. You expect them to return in {RETURN_DAYS} days with the news of success and {REWARD_GOLD}{GOLD_ICON}.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.IssueOwner.CharacterObject, textObject, false);
					StringHelpers.SetCharacterProperties("COMPANION", base.AlternativeSolutionHero.CharacterObject, textObject, false);
					textObject.SetTextVariable("REWARD_GOLD", this.RewardGold);
					textObject.SetTextVariable("TROOP_COUNT", this.AlternativeSolutionSentTroops.TotalManCount - 1);
					textObject.SetTextVariable("RETURN_DAYS", base.GetTotalAlternativeSolutionDurationInDays());
					textObject.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					return textObject;
				}
			}

			// Token: 0x17000EAC RID: 3756
			// (get) Token: 0x060049C1 RID: 18881 RVA: 0x00154754 File Offset: 0x00152954
			public override TextObject IssueAlternativeSolutionSuccessLog
			{
				get
				{
					TextObject textObject = new TextObject("{=PHAm9BIp}{COMPANION.LINK} and the men you sent with {?COMPANION.GENDER}her{?}him{\\?} successfully protected the caravan. {QUEST_GIVER.LINK} is happy and sends you {?QUES_GIVER.GENDER}her{?}him{\\?} regards with {REWARD_GOLD}{GOLD_ICON} he promised.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.IssueOwner.CharacterObject, textObject, false);
					StringHelpers.SetCharacterProperties("COMPANION", base.AlternativeSolutionHero.CharacterObject, textObject, false);
					textObject.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					textObject.SetTextVariable("REWARD_GOLD", this.RewardGold);
					return textObject;
				}
			}

			// Token: 0x17000EAD RID: 3757
			// (get) Token: 0x060049C2 RID: 18882 RVA: 0x001547C1 File Offset: 0x001529C1
			public override TextObject IssuePlayerResponseAfterAlternativeExplanation
			{
				get
				{
					return new TextObject("{=DAYaprEi}Maybe I'll send someone to look.", null);
				}
			}

			// Token: 0x17000EAE RID: 3758
			// (get) Token: 0x060049C3 RID: 18883 RVA: 0x001547CE File Offset: 0x001529CE
			public override bool IsThereAlternativeSolution
			{
				get
				{
					return true;
				}
			}

			// Token: 0x17000EAF RID: 3759
			// (get) Token: 0x060049C4 RID: 18884 RVA: 0x001547D1 File Offset: 0x001529D1
			public override int AlternativeSolutionBaseNeededMenCount
			{
				get
				{
					return 22 + MathF.Ceiling(30f * base.IssueDifficultyMultiplier);
				}
			}

			// Token: 0x17000EB0 RID: 3760
			// (get) Token: 0x060049C5 RID: 18885 RVA: 0x001547E7 File Offset: 0x001529E7
			protected override int AlternativeSolutionBaseDurationInDaysInternal
			{
				get
				{
					return 3 + MathF.Ceiling(5f * base.IssueDifficultyMultiplier);
				}
			}

			// Token: 0x17000EB1 RID: 3761
			// (get) Token: 0x060049C6 RID: 18886 RVA: 0x001547FC File Offset: 0x001529FC
			protected override int RewardGold
			{
				get
				{
					return (int)(1000f + 3000f * base.IssueDifficultyMultiplier);
				}
			}

			// Token: 0x060049C7 RID: 18887 RVA: 0x00154811 File Offset: 0x00152A11
			public CaravanAmbushIssue(Hero issueOwner, Settlement targetSettlement) : base(issueOwner, CampaignTime.DaysFromNow(20f))
			{
				this._targetSettlement = targetSettlement;
			}

			// Token: 0x060049C8 RID: 18888 RVA: 0x0015482B File Offset: 0x00152A2B
			protected override float GetIssueEffectAmountInternal(IssueEffect issueEffect)
			{
				if (issueEffect == DefaultIssueEffects.SettlementProsperity)
				{
					return -0.3f;
				}
				if (issueEffect == DefaultIssueEffects.SettlementSecurity)
				{
					return -1f;
				}
				if (issueEffect == DefaultIssueEffects.IssueOwnerPower)
				{
					return -0.2f;
				}
				return 0f;
			}

			// Token: 0x060049C9 RID: 18889 RVA: 0x0015485C File Offset: 0x00152A5C
			public override ValueTuple<SkillObject, int> GetAlternativeSolutionSkill(Hero hero)
			{
				return new ValueTuple<SkillObject, int>((hero.GetSkillValue(DefaultSkills.Tactics) >= hero.GetSkillValue(DefaultSkills.Roguery)) ? DefaultSkills.Tactics : DefaultSkills.Roguery, 120);
			}

			// Token: 0x060049CA RID: 18890 RVA: 0x00154889 File Offset: 0x00152A89
			protected override void OnGameLoad()
			{
			}

			// Token: 0x060049CB RID: 18891 RVA: 0x0015488B File Offset: 0x00152A8B
			protected override void HourlyTick()
			{
			}

			// Token: 0x060049CC RID: 18892 RVA: 0x00154890 File Offset: 0x00152A90
			protected override QuestBase GenerateIssueQuest(string questId)
			{
				return new CaravanAmbushIssueBehavior.CaravanAmbushIssueQuest("caravan_ambush_quest_" + CampaignTime.Now.ElapsedSecondsUntilNow, base.IssueOwner, this._targetSettlement, CampaignTime.DaysFromNow(20f), this.RewardGold, base.IssueDifficultyMultiplier);
			}

			// Token: 0x060049CD RID: 18893 RVA: 0x001548E0 File Offset: 0x00152AE0
			public override IssueBase.IssueFrequency GetFrequency()
			{
				return IssueBase.IssueFrequency.Common;
			}

			// Token: 0x060049CE RID: 18894 RVA: 0x001548E4 File Offset: 0x00152AE4
			protected override bool CanPlayerTakeQuestConditions(Hero issueGiver, out IssueBase.PreconditionFlags flag, out Hero relationHero, out SkillObject skill)
			{
				flag = IssueBase.PreconditionFlags.None;
				relationHero = issueGiver;
				skill = null;
				if (issueGiver.GetRelationWithPlayer() < -10f)
				{
					flag |= IssueBase.PreconditionFlags.Relation;
				}
				if (issueGiver.MapFaction.IsAtWarWith(Hero.MainHero.MapFaction))
				{
					flag |= IssueBase.PreconditionFlags.AtWar;
				}
				if (MobileParty.MainParty.MemberRoster.TotalHealthyCount < 30)
				{
					flag |= IssueBase.PreconditionFlags.NotEnoughTroops;
				}
				return flag == IssueBase.PreconditionFlags.None;
			}

			// Token: 0x060049CF RID: 18895 RVA: 0x0015494E File Offset: 0x00152B4E
			public override bool IssueStayAliveConditions()
			{
				return base.IssueOwner != null && base.IssueOwner.OwnedCaravans.Count > 0 && !base.IssueOwner.MapFaction.IsAtWarWith(Clan.PlayerClan);
			}

			// Token: 0x060049D0 RID: 18896 RVA: 0x00154985 File Offset: 0x00152B85
			public override bool DoTroopsSatisfyAlternativeSolution(TroopRoster troopRoster, out TextObject explanation)
			{
				explanation = TextObject.Empty;
				return QuestHelper.CheckRosterForAlternativeSolution(troopRoster, base.GetTotalAlternativeSolutionNeededMenCount(), ref explanation, 2, false);
			}

			// Token: 0x060049D1 RID: 18897 RVA: 0x0015499D File Offset: 0x00152B9D
			public override bool IsTroopTypeNeededByAlternativeSolution(CharacterObject character)
			{
				return character.Tier >= 2;
			}

			// Token: 0x060049D2 RID: 18898 RVA: 0x001549AB File Offset: 0x00152BAB
			protected override void CompleteIssueWithTimedOutConsequences()
			{
			}

			// Token: 0x060049D3 RID: 18899 RVA: 0x001549AD File Offset: 0x00152BAD
			public override bool AlternativeSolutionCondition(out TextObject explanation)
			{
				explanation = TextObject.Empty;
				return QuestHelper.CheckRosterForAlternativeSolution(MobileParty.MainParty.MemberRoster, base.GetTotalAlternativeSolutionNeededMenCount(), ref explanation, 2, false);
			}

			// Token: 0x060049D4 RID: 18900 RVA: 0x001549D0 File Offset: 0x00152BD0
			protected override void AlternativeSolutionEndWithSuccessConsequence()
			{
				base.AlternativeSolutionHero.AddSkillXp(DefaultSkills.Scouting, (float)((int)(600f + 800f * base.IssueDifficultyMultiplier)));
				float randomFloat = MBRandom.RandomFloat;
				SkillObject skill;
				if (randomFloat > 0.66f)
				{
					skill = DefaultSkills.OneHanded;
				}
				else if (randomFloat <= 0.66f && randomFloat > 0.33f)
				{
					skill = DefaultSkills.TwoHanded;
				}
				else
				{
					skill = DefaultSkills.Polearm;
				}
				base.AlternativeSolutionHero.AddSkillXp(skill, (float)((int)(600f + 800f * base.IssueDifficultyMultiplier)));
				Clan.PlayerClan.AddRenown(3f, true);
				this.RelationshipChangeWithIssueOwner = 5;
			}

			// Token: 0x060049D5 RID: 18901 RVA: 0x00154A6C File Offset: 0x00152C6C
			protected override void AlternativeSolutionEndWithFailureConsequence()
			{
				this.RelationshipChangeWithIssueOwner = -5;
				base.IssueOwner.AddPower(-5f);
			}

			// Token: 0x04001912 RID: 6418
			private const float CaravanAmbushIssueDurationInDays = 20f;

			// Token: 0x04001913 RID: 6419
			private const int AlternativeSolutionMinimumTroopTier = 2;

			// Token: 0x04001914 RID: 6420
			private const int AlternativeSolutionRenownReward = 3;

			// Token: 0x04001915 RID: 6421
			private const int AlternativeSolutionRelationReward = 5;

			// Token: 0x04001916 RID: 6422
			private const int AlternativeSolutionRelationPenalty = -5;

			// Token: 0x04001917 RID: 6423
			private const int CaravanAmbushIssueNotableMinimumRelation = -10;

			// Token: 0x04001918 RID: 6424
			private const int CompanionSkill = 120;

			// Token: 0x04001919 RID: 6425
			private const int MinimumRequiredMenCount = 30;

			// Token: 0x0400191A RID: 6426
			[SaveableField(1)]
			private readonly Settlement _targetSettlement;
		}

		// Token: 0x02000612 RID: 1554
		public class CaravanAmbushIssueQuest : QuestBase
		{
			// Token: 0x060049D6 RID: 18902 RVA: 0x00154A86 File Offset: 0x00152C86
			internal static void AutoGeneratedStaticCollectObjectsCaravanAmbushIssueQuest(object o, List<object> collectedObjects)
			{
				((CaravanAmbushIssueBehavior.CaravanAmbushIssueQuest)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
			}

			// Token: 0x060049D7 RID: 18903 RVA: 0x00154A94 File Offset: 0x00152C94
			protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
			{
				base.AutoGeneratedInstanceCollectObjects(collectedObjects);
				collectedObjects.Add(this._targetSettlement);
				collectedObjects.Add(this._caravanParty);
				collectedObjects.Add(this._banditParty);
				collectedObjects.Add(this._rewardItems);
				CampaignTime.AutoGeneratedStaticCollectObjectsCampaignTime(this._vicinityCheckDisabledUntil, collectedObjects);
			}

			// Token: 0x060049D8 RID: 18904 RVA: 0x00154AE9 File Offset: 0x00152CE9
			internal static object AutoGeneratedGetMemberValue_targetSettlement(object o)
			{
				return ((CaravanAmbushIssueBehavior.CaravanAmbushIssueQuest)o)._targetSettlement;
			}

			// Token: 0x060049D9 RID: 18905 RVA: 0x00154AF6 File Offset: 0x00152CF6
			internal static object AutoGeneratedGetMemberValue_issueDifficulty(object o)
			{
				return ((CaravanAmbushIssueBehavior.CaravanAmbushIssueQuest)o)._issueDifficulty;
			}

			// Token: 0x060049DA RID: 18906 RVA: 0x00154B08 File Offset: 0x00152D08
			internal static object AutoGeneratedGetMemberValue_caravanParty(object o)
			{
				return ((CaravanAmbushIssueBehavior.CaravanAmbushIssueQuest)o)._caravanParty;
			}

			// Token: 0x060049DB RID: 18907 RVA: 0x00154B15 File Offset: 0x00152D15
			internal static object AutoGeneratedGetMemberValue_banditParty(object o)
			{
				return ((CaravanAmbushIssueBehavior.CaravanAmbushIssueQuest)o)._banditParty;
			}

			// Token: 0x060049DC RID: 18908 RVA: 0x00154B22 File Offset: 0x00152D22
			internal static object AutoGeneratedGetMemberValue_vicinityCheckFailCounter(object o)
			{
				return ((CaravanAmbushIssueBehavior.CaravanAmbushIssueQuest)o)._vicinityCheckFailCounter;
			}

			// Token: 0x060049DD RID: 18909 RVA: 0x00154B34 File Offset: 0x00152D34
			internal static object AutoGeneratedGetMemberValue_rewardItems(object o)
			{
				return ((CaravanAmbushIssueBehavior.CaravanAmbushIssueQuest)o)._rewardItems;
			}

			// Token: 0x060049DE RID: 18910 RVA: 0x00154B41 File Offset: 0x00152D41
			internal static object AutoGeneratedGetMemberValue_isCaravanSaved(object o)
			{
				return ((CaravanAmbushIssueBehavior.CaravanAmbushIssueQuest)o)._isCaravanSaved;
			}

			// Token: 0x060049DF RID: 18911 RVA: 0x00154B53 File Offset: 0x00152D53
			internal static object AutoGeneratedGetMemberValue_vicinityCheckDisabledUntil(object o)
			{
				return ((CaravanAmbushIssueBehavior.CaravanAmbushIssueQuest)o)._vicinityCheckDisabledUntil;
			}

			// Token: 0x060049E0 RID: 18912 RVA: 0x00154B65 File Offset: 0x00152D65
			internal static object AutoGeneratedGetMemberValue_isCaravanWaitingForEscort(object o)
			{
				return ((CaravanAmbushIssueBehavior.CaravanAmbushIssueQuest)o)._isCaravanWaitingForEscort;
			}

			// Token: 0x17000EB2 RID: 3762
			// (get) Token: 0x060049E1 RID: 18913 RVA: 0x00154B77 File Offset: 0x00152D77
			private int CaravanPartyTroopCount
			{
				get
				{
					return 22 + MathF.Ceiling(30f * this._issueDifficulty);
				}
			}

			// Token: 0x17000EB3 RID: 3763
			// (get) Token: 0x060049E2 RID: 18914 RVA: 0x00154B8D File Offset: 0x00152D8D
			private int BanditPartyTroopCount
			{
				get
				{
					return 25 + MathF.Ceiling(50f * this._issueDifficulty);
				}
			}

			// Token: 0x17000EB4 RID: 3764
			// (get) Token: 0x060049E3 RID: 18915 RVA: 0x00154BA3 File Offset: 0x00152DA3
			public override TextObject Title
			{
				get
				{
					return new TextObject("{=wF7uiYzy}Caravan Ambush", null);
				}
			}

			// Token: 0x17000EB5 RID: 3765
			// (get) Token: 0x060049E4 RID: 18916 RVA: 0x00154BB0 File Offset: 0x00152DB0
			public override bool IsRemainingTimeHidden
			{
				get
				{
					return false;
				}
			}

			// Token: 0x17000EB6 RID: 3766
			// (get) Token: 0x060049E5 RID: 18917 RVA: 0x00154BB4 File Offset: 0x00152DB4
			private TextObject _caravanAmbushIssueQuestActivatedLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=S4kpdrgw}{QUEST_GIVER.LINK}, {?IS_ARTISAN}an artisan{?}a merchant{\\?} from {SETTLEMENT}, asked you to follow a fake caravan that was bait for a particularly large and dangerous group of bandits. {?QUEST_GIVER.GENDER}She{?}He{\\?} suspects this fake caravan will be attacked on its way to {TARGET_SETTLEMENT}, so {?QUEST_GIVER.GENDER}she{?}he{\\?} wants you to follow the caravan from a safe distance and join in the fight once it is attacked. If you succeed, {?QUEST_GIVER.GENDER}she{?}he{\\?} promised to pay you {REWARD_GOLD}{GOLD_ICON}. ", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					textObject.SetTextVariable("IS_ARTISAN", base.QuestGiver.IsArtisan ? 1 : 0);
					textObject.SetTextVariable("SETTLEMENT", base.QuestGiver.CurrentSettlement.EncyclopediaLinkWithName);
					textObject.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.EncyclopediaLinkWithName);
					textObject.SetTextVariable("REWARD_GOLD", this.RewardGold);
					textObject.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					return textObject;
				}
			}

			// Token: 0x17000EB7 RID: 3767
			// (get) Token: 0x060049E6 RID: 18918 RVA: 0x00154C5C File Offset: 0x00152E5C
			private TextObject _caravanAmbushIssueQuestSucceededLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=g5bRX0dd}You have defeated the large group of bandits that {QUEST_GIVER.LINK} mentioned and {?QUEST_GIVER.GENDER}she{?}he{\\?} sends {?QUEST_GIVER.GENDER}her{?}his{\\?} regards with the {REWARD_GOLD}{GOLD_ICON} {?QUEST_GIVER.GENDER}she{?}he{\\?} promised and some trade goods as reward.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					textObject.SetTextVariable("REWARD_GOLD", this.RewardGold);
					textObject.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					return textObject;
				}
			}

			// Token: 0x17000EB8 RID: 3768
			// (get) Token: 0x060049E7 RID: 18919 RVA: 0x00154CB4 File Offset: 0x00152EB4
			private TextObject _caravanAmbushIssueQuestVicinityCheckFailedLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=DbXMSRmA}You got too close to the caravan. The bandits saw you and withdrew. {QUEST_GIVER.LINK}'s plan failed and {?QUEST_GIVER.GENDER}she{?}he{\\?} will be very upset.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17000EB9 RID: 3769
			// (get) Token: 0x060049E8 RID: 18920 RVA: 0x00154CE8 File Offset: 0x00152EE8
			private TextObject _caravanAmbushIssueQuestCaravanDestroyedLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=WtCSdcs9}You have failed to defeat the bandits, as {QUEST_GIVER.LINK} asked you to do.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17000EBA RID: 3770
			// (get) Token: 0x060049E9 RID: 18921 RVA: 0x00154D1C File Offset: 0x00152F1C
			private TextObject _caravanAmbushIssueQuestTimeOutLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=qi0wKvPX}You failed to catch up to the caravan before it was overwhelmed. {QUEST_GIVER.LINK} will be very upset about this.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17000EBB RID: 3771
			// (get) Token: 0x060049EA RID: 18922 RVA: 0x00154D50 File Offset: 0x00152F50
			private TextObject _caravanSurvivedWithoutHelpLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=UFce0iyy}The caravan survived the battle without your help. You failed to keep your promise to {QUEST_GIVER.LINK}.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17000EBC RID: 3772
			// (get) Token: 0x060049EB RID: 18923 RVA: 0x00154D84 File Offset: 0x00152F84
			private TextObject _caravanAmbushIssueQuestHiredBanditsLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=bdab7SmZ}You recruited the bandits who were giving {QUEST_GIVER.LINK} trouble. {?QUEST_GIVER.GENDER}she{?}he{\\?} is satisfied with this outcome, and sends you {REWARD_GOLD}{GOLD_ICON} that {?QUEST_GIVER.GENDER}she{?}he{\\?} promised.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					textObject.SetTextVariable("REWARD_GOLD", this.RewardGold);
					textObject.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					return textObject;
				}
			}

			// Token: 0x17000EBD RID: 3773
			// (get) Token: 0x060049EC RID: 18924 RVA: 0x00154DD9 File Offset: 0x00152FD9
			private TextObject _caravanAmbushWarDeclaredCancelLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=dQl0Bnwm}Your clan is now at war with the {QUEST_GIVER.LINK}'s faction. Your agreement with {QUEST_GIVER.LINK} has been canceled.", null);
					textObject.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, false);
					return textObject;
				}
			}

			// Token: 0x060049ED RID: 18925 RVA: 0x00154DFD File Offset: 0x00152FFD
			public CaravanAmbushIssueQuest(string questId, Hero questGiver, Settlement targetSettlement, CampaignTime duration, int rewardGold, float issueDifficulty) : base(questId, questGiver, duration, rewardGold)
			{
				this._targetSettlement = targetSettlement;
				this._issueDifficulty = issueDifficulty;
				this.SetDialogs();
				base.InitializeQuestOnCreation();
			}

			// Token: 0x060049EE RID: 18926 RVA: 0x00154E34 File Offset: 0x00153034
			protected override void SetDialogs()
			{
				this.OfferDialogFlow = DialogFlow.CreateDialogFlow("issue_classic_quest_start", 100).NpcLine("{=1sbbbOyr}Excellent... I'm counting on you! The caravan will be leaving soon.[if:convo_normal][ib:hip]", null, null).Condition(() => Hero.OneToOneConversationHero == base.QuestGiver).Consequence(new ConversationSentence.OnConsequenceDelegate(this.OnQuestAccepted)).CloseDialog();
				this.DiscussDialogFlow = DialogFlow.CreateDialogFlow("quest_discuss", 100).NpcLine("{=5o9udV96}Yes? You should go already. The caravan is on its way.[if:convo_annoyed][ib:normal2]", null, null).Condition(() => Hero.OneToOneConversationHero == base.QuestGiver && !this._isCaravanSaved).BeginPlayerOptions().PlayerOption("{=DKiLA9f2}Don't worry, I'll find them.", null).NpcLine("{=ddEu5IFQ}I hope so.", null, null).CloseDialog().PlayerOption("{=zpqP5LsC}I'll go right away.", null).NpcLine("{=3ssQAe1t}Good to hear that", null, null).CloseDialog().EndPlayerOptions().CloseDialog();
				Campaign.Current.ConversationManager.AddDialogFlow(this.GetCaravaneerDialogFlow(), this);
			}

			// Token: 0x060049EF RID: 18927 RVA: 0x00154F14 File Offset: 0x00153114
			private DialogFlow GetCaravaneerDialogFlow()
			{
				return DialogFlow.CreateDialogFlow("start", 125).NpcLine("{=LqEdr7sQ}Thank you, {?PLAYER.GENDER}milady{?}sir{\\?}. {QUEST_GIVER.LINK} had informed me that help would be on the way. We needed it, I think. Those were a pretty tough lot.", null, null).Condition(delegate
				{
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, null, false);
					return CharacterObject.OneToOneConversationCharacter == ConversationHelper.GetConversationCharacterPartyLeader(this._caravanParty.Party) && this._isCaravanSaved;
				}).PlayerLine("{=MKbLhn9d}I'm glad we caught up to you in time.", null).NpcLine("{=yxg91L0a}We'll tell everyone what you did.[if:convo_happy][ib:normal2] Please take some of these goods in compensation. We have no intention to sell them anyway. Safe travels, {?PLAYER.GENDER}milady{?}sir{\\?}.", null, null).Consequence(delegate
				{
					Campaign.Current.ConversationManager.ConversationEndOneShot += this.OnQuestSucceeded;
				}).CloseDialog();
			}

			// Token: 0x060049F0 RID: 18928 RVA: 0x00154F78 File Offset: 0x00153178
			private void OnQuestAccepted()
			{
				base.StartQuest();
				base.AddLog(this._caravanAmbushIssueQuestActivatedLogText, false);
				ItemRoster itemRoster = new ItemRoster();
				itemRoster.AddToCounts(MBObjectManager.Instance.GetObject<ItemObject>("fish"), 20);
				itemRoster.AddToCounts(MBObjectManager.Instance.GetObject<ItemObject>("grain"), 40);
				itemRoster.AddToCounts(MBObjectManager.Instance.GetObject<ItemObject>("butter"), 20);
				itemRoster.AddToCounts(DefaultItems.HardWood, 60);
				this._caravanParty = CaravanPartyComponent.CreateCaravanParty(base.QuestGiver, base.QuestGiver.CurrentSettlement, false, null, itemRoster, 0, false);
				this._caravanParty.MemberRoster.Clear();
				this._caravanParty.MemberRoster.AddToCounts(base.QuestGiver.Culture.CaravanMaster, 1, false, 0, 0, true, -1);
				this._caravanParty.MemberRoster.AddToCounts(base.QuestGiver.Culture.BasicTroop, this.CaravanPartyTroopCount, false, 0, 0, true, -1);
				this._caravanParty.IgnoreByOtherPartiesTill(base.QuestDueTime);
				Campaign.Current.MobilePartyLocator.UpdateLocator(this._caravanParty);
				SetPartyAiAction.GetActionForVisitingSettlement(this._caravanParty, this._targetSettlement);
				this._caravanParty.Ai.SetDoNotMakeNewDecisions(true);
				this._caravanParty.SetPartyUsedByQuest(true);
				base.AddTrackedObject(this._caravanParty);
				MobilePartyHelper.TryMatchPartySpeedWithItemWeight(this._caravanParty, MobileParty.MainParty.Speed * 0.7f, null);
				Settlement settlement = SettlementHelper.FindNearestHideout((Settlement x) => x.IsActive, null);
				Clan clan = Clan.BanditFactions.FirstOrDefault((Clan x) => x.StringId == "looters");
				this._banditParty = BanditPartyComponent.CreateBanditParty("caravan_ambush_quest_" + clan.Name, clan, settlement.Hideout, false);
				Vec2 gatePosition = this._targetSettlement.GatePosition;
				PartyTemplateObject partyTemplateObject = Campaign.Current.ObjectManager.GetObject<PartyTemplateObject>("kingdom_hero_party_caravan_ambushers") ?? clan.DefaultPartyTemplate;
				this._banditParty.InitializeMobilePartyAroundPosition(partyTemplateObject, gatePosition, 0.2f, 0.1f, -1);
				this._banditParty.SetCustomName(new TextObject("{=u1Pkt4HC}Raiders", null));
				Campaign.Current.MobilePartyLocator.UpdateLocator(this._banditParty);
				this._banditParty.MemberRoster.Clear();
				this._banditParty.SetPartyUsedByQuest(true);
				for (int i = 0; i < this.BanditPartyTroopCount; i++)
				{
					List<ValueTuple<PartyTemplateStack, float>> list = new List<ValueTuple<PartyTemplateStack, float>>();
					foreach (PartyTemplateStack partyTemplateStack in partyTemplateObject.Stacks)
					{
						list.Add(new ValueTuple<PartyTemplateStack, float>(partyTemplateStack, (float)(64 - partyTemplateStack.Character.Level)));
					}
					PartyTemplateStack partyTemplateStack2 = MBRandom.ChooseWeighted<PartyTemplateStack>(list);
					this._banditParty.MemberRoster.AddToCounts(partyTemplateStack2.Character, 1, false, 0, 0, true, -1);
				}
				this._banditParty.ItemRoster.AddToCounts(MBObjectManager.Instance.GetObject<ItemObject>("sumpter_horse"), this.BanditPartyTroopCount / 4);
				this._banditParty.IgnoreByOtherPartiesTill(base.QuestDueTime);
				SetPartyAiAction.GetActionForEngagingParty(this._banditParty, this._caravanParty);
				this._banditParty.Ai.SetDoNotMakeNewDecisions(true);
				for (int j = 0; j < 3; j++)
				{
					this._rewardItems.Add(Items.All.GetRandomElementWithPredicate((ItemObject t) => t.IsTradeGood && !t.NotMerchandise));
				}
				this._vicinityCheckDisabledUntil = CampaignTime.HoursFromNow(1f);
			}

			// Token: 0x060049F1 RID: 18929 RVA: 0x00155350 File Offset: 0x00153550
			private void OnQuestSucceeded()
			{
				base.AddLog(this._caravanAmbushIssueQuestSucceededLogText, false);
				GiveGoldAction.ApplyBetweenCharacters(null, Hero.MainHero, this.RewardGold, false);
				this.RelationshipChangeWithQuestGiver = 5;
				Clan.PlayerClan.AddRenown(3f, true);
				foreach (ItemObject item in this._rewardItems)
				{
					MobileParty.MainParty.ItemRoster.AddToCounts(item, 1);
				}
				if (PlayerEncounter.Current != null)
				{
					PlayerEncounter.LeaveEncounter = true;
				}
				base.CompleteQuestWithSuccess();
			}

			// Token: 0x060049F2 RID: 18930 RVA: 0x001553F8 File Offset: 0x001535F8
			private void OnPlayerHiredBandits()
			{
				base.AddLog(this._caravanAmbushIssueQuestHiredBanditsLogText, false);
				GiveGoldAction.ApplyBetweenCharacters(null, Hero.MainHero, this.RewardGold, false);
				this.RelationshipChangeWithQuestGiver = 5;
				Clan.PlayerClan.AddRenown(3f, true);
				if (PlayerEncounter.Current != null)
				{
					PlayerEncounter.LeaveEncounter = true;
				}
				base.CompleteQuestWithSuccess();
			}

			// Token: 0x060049F3 RID: 18931 RVA: 0x00155450 File Offset: 0x00153650
			protected override void HourlyTick()
			{
				if (this._caravanParty != null && this._banditParty != null && base.IsOngoing)
				{
					if (this._caravanParty.MapEvent == null && !this._isCaravanSaved)
					{
						if (this._caravanParty.Position2D.DistanceSquared(base.QuestGiver.CurrentSettlement.GatePosition) >= 100f && this._caravanParty.Position2D.DistanceSquared(MobileParty.MainParty.Position2D) <= 9f && this._vicinityCheckDisabledUntil.IsPast)
						{
							MBInformationManager.AddQuickInformation(new TextObject("{=ki1CWgcP}Warning! You are too close to the caravan. Stay a bit farther away.", null), 0, null, "");
							this._vicinityCheckFailCounter++;
							if (this._vicinityCheckFailCounter >= 5)
							{
								this.OnFailedVicinityChecks();
							}
						}
						MobilePartyHelper.UtilizePartyEscortBehavior(this._caravanParty, MobileParty.MainParty, ref this._isCaravanWaitingForEscort, 6.3f, 7.1f, new MobilePartyHelper.ResumePartyEscortBehaviorDelegate(this.ResumeCaravanMovement), false);
						if (this._caravanParty.Position2D.DistanceSquared(this._banditParty.Position2D) <= 7f)
						{
							EncounterManager.StartPartyEncounter(this._banditParty.Party, this._caravanParty.Party);
						}
					}
					if (this._caravanParty.MapEvent != null && this._caravanParty.MapEvent.IsInvulnerable && this._caravanParty.MapEvent.BattleStartTime.ElapsedHoursUntilNow > 6f)
					{
						this._caravanParty.MapEvent.IsInvulnerable = false;
					}
				}
			}

			// Token: 0x060049F4 RID: 18932 RVA: 0x001555E4 File Offset: 0x001537E4
			private void ResumeCaravanMovement()
			{
				SetPartyAiAction.GetActionForVisitingSettlement(this._caravanParty, this._targetSettlement);
			}

			// Token: 0x060049F5 RID: 18933 RVA: 0x001555F7 File Offset: 0x001537F7
			private void OnFailedVicinityChecks()
			{
				base.AddLog(this._caravanAmbushIssueQuestVicinityCheckFailedLogText, false);
				this.RelationshipChangeWithQuestGiver = -5;
				base.QuestGiver.AddPower(-5f);
				this.HandlePartyAiAfterCompletion();
				base.CompleteQuestWithFail(null);
			}

			// Token: 0x060049F6 RID: 18934 RVA: 0x0015562C File Offset: 0x0015382C
			protected override void OnTimedOut()
			{
				base.AddLog(this._caravanAmbushIssueQuestTimeOutLogText, false);
				this.RelationshipChangeWithQuestGiver = -5;
				base.QuestGiver.AddPower(-5f);
			}

			// Token: 0x060049F7 RID: 18935 RVA: 0x00155654 File Offset: 0x00153854
			private void OnSettlementEntered(MobileParty party, Settlement settlement, Hero hero)
			{
				if (party == this._caravanParty)
				{
					Debug.FailedAssert("Caravan has arrived at settlement without encountering the bandits", "C:\\Develop\\MB3\\Source\\Bannerlord\\TaleWorlds.CampaignSystem\\Issues\\CaravanAmbushIssueBehavior.cs", "OnSettlementEntered", 698);
					DestroyPartyAction.Apply(this._caravanParty.Party, this._caravanParty);
					this._caravanParty = null;
					this._banditParty.Ai.SetDoNotMakeNewDecisions(false);
					base.CompleteQuestWithCancel(null);
				}
			}

			// Token: 0x060049F8 RID: 18936 RVA: 0x001556B8 File Offset: 0x001538B8
			protected override void RegisterEvents()
			{
				CampaignEvents.MapEventEnded.AddNonSerializedListener(this, new Action<MapEvent>(this.MapEventEnded));
				CampaignEvents.MapEventStarted.AddNonSerializedListener(this, new Action<MapEvent, PartyBase, PartyBase>(this.MapEventStarted));
				CampaignEvents.SettlementEntered.AddNonSerializedListener(this, new Action<MobileParty, Settlement, Hero>(this.OnSettlementEntered));
				CampaignEvents.BanditPartyRecruited.AddNonSerializedListener(this, new Action<MobileParty>(this.OnBanditPartyRecruited));
				CampaignEvents.WarDeclared.AddNonSerializedListener(this, new Action<IFaction, IFaction, DeclareWarAction.DeclareWarDetail>(this.OnWarDeclared));
				CampaignEvents.OnClanChangedKingdomEvent.AddNonSerializedListener(this, new Action<Clan, Kingdom, Kingdom, ChangeKingdomAction.ChangeKingdomActionDetail, bool>(this.OnClanChangedKingdom));
			}

			// Token: 0x060049F9 RID: 18937 RVA: 0x0015574F File Offset: 0x0015394F
			private void OnBanditPartyRecruited(MobileParty party)
			{
				if (party == this._banditParty)
				{
					this.OnPlayerHiredBandits();
				}
			}

			// Token: 0x060049FA RID: 18938 RVA: 0x00155760 File Offset: 0x00153960
			private void OnWarDeclared(IFaction faction1, IFaction faction2, DeclareWarAction.DeclareWarDetail declareWarDetail)
			{
				if (base.QuestGiver.CurrentSettlement.MapFaction.IsAtWarWith(Clan.PlayerClan.MapFaction))
				{
					base.CompleteQuestWithCancel(this._caravanAmbushWarDeclaredCancelLogText);
				}
			}

			// Token: 0x060049FB RID: 18939 RVA: 0x00155790 File Offset: 0x00153990
			private void MapEventEnded(MapEvent mapEvent)
			{
				if (mapEvent.WinningSide != BattleSideEnum.None && mapEvent.DefeatedSide != BattleSideEnum.None)
				{
					MapEventSide mapEventSide = mapEvent.GetMapEventSide(mapEvent.WinningSide);
					MapEventSide mapEventSide2 = mapEvent.GetMapEventSide(mapEvent.DefeatedSide);
					if (mapEventSide2.Parties.Any((MapEventParty t) => t.Party == this._caravanParty.Party))
					{
						this.HandlePartyAiAfterCompletion();
						this.OnCaravanDestroyed(mapEventSide.LeaderParty);
						return;
					}
					if (mapEventSide2.Parties.Any((MapEventParty t) => t.Party == this._banditParty.Party))
					{
						this._isCaravanSaved = true;
						this.HandlePartyAiAfterCompletion();
						if (mapEventSide.IsMainPartyAmongParties())
						{
							if (this._caravanParty.IsActive && mapEventSide.Parties.Any((MapEventParty t) => t.Party == this._caravanParty.Party))
							{
								CampaignMapConversation.OpenConversation(new ConversationCharacterData(Hero.MainHero.CharacterObject, null, false, false, false, false, false, false), new ConversationCharacterData(ConversationHelper.GetConversationCharacterPartyLeader(this._caravanParty.Party), null, false, false, false, false, false, false));
								return;
							}
							this.OnQuestSucceeded();
							return;
						}
						else
						{
							this.OnCaravanSurvivedWithoutHelp();
						}
					}
				}
			}

			// Token: 0x060049FC RID: 18940 RVA: 0x00155897 File Offset: 0x00153A97
			private void OnWarDeclared(IFaction faction1, IFaction faction2)
			{
				this.CheckFailureDueToDiplomaticState();
			}

			// Token: 0x060049FD RID: 18941 RVA: 0x0015589F File Offset: 0x00153A9F
			private void OnClanChangedKingdom(Clan clan, Kingdom oldKingdom, Kingdom newKingdom, ChangeKingdomAction.ChangeKingdomActionDetail detail, bool showNotification = true)
			{
				if (clan == Clan.PlayerClan && newKingdom != null)
				{
					this.CheckFailureDueToDiplomaticState();
				}
			}

			// Token: 0x060049FE RID: 18942 RVA: 0x001558B2 File Offset: 0x00153AB2
			private void CheckFailureDueToDiplomaticState()
			{
				if (base.QuestGiver.CurrentSettlement.MapFaction.IsAtWarWith(Clan.PlayerClan.MapFaction))
				{
					base.CompleteQuestWithCancel(this._caravanAmbushWarDeclaredCancelLogText);
				}
			}

			// Token: 0x060049FF RID: 18943 RVA: 0x001558E1 File Offset: 0x00153AE1
			private void MapEventStarted(MapEvent mapEvent, PartyBase attackerParty, PartyBase defenderParty)
			{
				if (defenderParty.MobileParty == this._caravanParty && attackerParty.MobileParty == this._banditParty)
				{
					mapEvent.IsInvulnerable = true;
				}
			}

			// Token: 0x06004A00 RID: 18944 RVA: 0x00155906 File Offset: 0x00153B06
			private void OnCaravanSurvivedWithoutHelp()
			{
				base.AddLog(this._caravanSurvivedWithoutHelpLogText, false);
				ChangeRelationAction.ApplyPlayerRelation(base.QuestGiver, -5, true, true);
				base.QuestGiver.AddPower(-5f);
				this.HandlePartyAiAfterCompletion();
				base.CompleteQuestWithFail(null);
			}

			// Token: 0x06004A01 RID: 18945 RVA: 0x00155944 File Offset: 0x00153B44
			private void OnCaravanDestroyed(PartyBase destroyerParty)
			{
				base.AddLog(this._caravanAmbushIssueQuestCaravanDestroyedLogText, false);
				this.RelationshipChangeWithQuestGiver = -5;
				base.QuestGiver.AddPower(-5f);
				if (this._caravanParty.MapEvent != null)
				{
					this._caravanParty.MapEvent.IsInvulnerable = false;
				}
				this._caravanParty = null;
				base.CompleteQuestWithFail(null);
			}

			// Token: 0x06004A02 RID: 18946 RVA: 0x001559A4 File Offset: 0x00153BA4
			private void HandlePartyAiAfterCompletion()
			{
				if (this._caravanParty.IsActive)
				{
					this._caravanParty.Ai.SetDoNotMakeNewDecisions(false);
					SetPartyAiAction.GetActionForVisitingSettlement(this._caravanParty, this._targetSettlement);
				}
				if (this._banditParty.IsActive)
				{
					this._banditParty.Ai.SetDoNotMakeNewDecisions(false);
					SetPartyAiAction.GetActionForVisitingSettlement(this._banditParty, this._banditParty.HomeSettlement);
					return;
				}
				this._banditParty = null;
			}

			// Token: 0x06004A03 RID: 18947 RVA: 0x00155A1C File Offset: 0x00153C1C
			protected override void InitializeQuestOnGameLoad()
			{
				this.SetDialogs();
				if (this._banditParty.MapEvent != null && this._banditParty.MapEvent.DefenderSide.LeaderParty.MobileParty != this._caravanParty)
				{
					this._banditParty.MapEvent.FinalizeEvent();
				}
				if (!this._banditParty.Ai.DoNotMakeNewDecisions || this._banditParty.TargetParty != this._caravanParty)
				{
					SetPartyAiAction.GetActionForEngagingParty(this._banditParty, this._caravanParty);
					this._banditParty.Ai.SetDoNotMakeNewDecisions(true);
					this._banditParty.IgnoreByOtherPartiesTill(base.QuestDueTime);
				}
			}

			// Token: 0x0400191B RID: 6427
			private const int VicinityCheckFailedRelationPenalty = -5;

			// Token: 0x0400191C RID: 6428
			private const int VicinityCheckFailedPowerPenalty = -5;

			// Token: 0x0400191D RID: 6429
			private const int CaravanDestroyedRelationPenalty = -5;

			// Token: 0x0400191E RID: 6430
			private const int CaravanDestroyedPowerPenalty = -5;

			// Token: 0x0400191F RID: 6431
			private const int TimeoutRelationPenalty = -5;

			// Token: 0x04001920 RID: 6432
			private const int TimeoutPowerPenalty = -5;

			// Token: 0x04001921 RID: 6433
			private const int QuestSucceededRelationReward = 5;

			// Token: 0x04001922 RID: 6434
			private const int QuestSucceededRenownReward = 3;

			// Token: 0x04001923 RID: 6435
			private const float VicinityCheckDistanceSquared = 9f;

			// Token: 0x04001924 RID: 6436
			private const int VicinityCheckFailThreshold = 5;

			// Token: 0x04001925 RID: 6437
			private const float CaravanWaitOnMapDurationInHours = 2f;

			// Token: 0x04001926 RID: 6438
			private const float CaravanWaitOnMapPeriodInHours = 6f;

			// Token: 0x04001927 RID: 6439
			private const int NumberOfRandomRewardItems = 3;

			// Token: 0x04001928 RID: 6440
			private const float MapEventInvulnerabilityDurationInHours = 6f;

			// Token: 0x04001929 RID: 6441
			private const float CaravanMainPartySpeedRatio = 0.7f;

			// Token: 0x0400192A RID: 6442
			private const float PartyEscortOuterRadius = 7.1f;

			// Token: 0x0400192B RID: 6443
			private const float PartyEscortInnerRadius = 6.3f;

			// Token: 0x0400192C RID: 6444
			[SaveableField(1)]
			private readonly Settlement _targetSettlement;

			// Token: 0x0400192D RID: 6445
			[SaveableField(2)]
			private readonly float _issueDifficulty;

			// Token: 0x0400192E RID: 6446
			[SaveableField(3)]
			private MobileParty _caravanParty;

			// Token: 0x0400192F RID: 6447
			[SaveableField(4)]
			private MobileParty _banditParty;

			// Token: 0x04001930 RID: 6448
			[SaveableField(5)]
			private int _vicinityCheckFailCounter;

			// Token: 0x04001931 RID: 6449
			[SaveableField(6)]
			private List<ItemObject> _rewardItems = new List<ItemObject>();

			// Token: 0x04001932 RID: 6450
			[SaveableField(7)]
			private bool _isCaravanSaved;

			// Token: 0x04001933 RID: 6451
			[SaveableField(8)]
			private CampaignTime _vicinityCheckDisabledUntil;

			// Token: 0x04001934 RID: 6452
			[SaveableField(10)]
			private bool _isCaravanWaitingForEscort;
		}

		// Token: 0x02000613 RID: 1555
		public class CaravanAmbushIssueTypeDefiner : SaveableTypeDefiner
		{
			// Token: 0x06004A0B RID: 18955 RVA: 0x00155B84 File Offset: 0x00153D84
			public CaravanAmbushIssueTypeDefiner() : base(380000)
			{
			}

			// Token: 0x06004A0C RID: 18956 RVA: 0x00155B91 File Offset: 0x00153D91
			protected override void DefineClassTypes()
			{
				base.AddClassDefinition(typeof(CaravanAmbushIssueBehavior.CaravanAmbushIssue), 1, null);
				base.AddClassDefinition(typeof(CaravanAmbushIssueBehavior.CaravanAmbushIssueQuest), 2, null);
			}
		}
	}
}
